package com.sfhk.web;

import com.sfhk.dao.impl.UserDaoImpl;
import com.sfhk.domain.User;
import com.sfhk.service.UserService;
import com.sfhk.service.impl.UserServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/UserListServlet")
public class UserListServlet extends HttpServlet {
    private UserService userService = new UserServiceImpl();
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // 1.接收请求
        // 2.调用service的方法
        List<User> list = userService.queryUser();
        // 3.request域传递数据
        request.setAttribute("list", list);
        // 4.转发到jsp中
        request.getRequestDispatcher("/list.jsp").forward(request, response);
        System.out.println(list.size());
    }

    public static void main(String[] args) {
//        List<User> list = new UserDaoImpl().findAll();
//        list.forEach(System.out::println);
        System.out.println(1);
    }
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request, response);
    }
}
